package array;

import arr.DynamicArray;

import java.util.Scanner;

/**
 * @author yyz
 * @create 2023-09-12 10:41
 */
public class Main {
    public static void main(String[] args) {
        boolean isFlag = true;
        Scanner s = new Scanner(System.in);
        DynamicArray array = new DynamicArray();
        int index, element;

        while (isFlag) {
            System.out.println("\n\t=====线性表操作菜单====\t");
            System.out.println("1.显示数据");
            System.out.println("2.添加数据");
            System.out.println("3.插入数据");
            System.out.println("4.删除数据");
            System.out.println("5.退出");

            System.out.print("请输入:");
            int number = s.nextInt();

            switch (number) {
                case 1:
                    array.foreach(ele -> {
                        System.out.println(ele + "\t");
                    });
//                    array.stream().forEach(System.out::println);
//                    for (Integer integer : array) {
//                        System.out.println(integer);
//                    }
                    break;
                case 2:
                    System.out.print("输入数据：");
                    element = s.nextInt();
                    array.add(element);
                    break;
                case 3:
                    System.out.print("输入索引：");
                    index = s.nextInt();
                    System.out.print("输入数据：");
                    element = s.nextInt();
                    array.insert(index, element);
                    break;
                case 4://删除数据
                    System.out.print("输入索引：");
                    index = s.nextInt();
                    array.remove(index);
                    break;
                case 5://退出
                    System.out.println("退出");
                    isFlag = false;
            }
        }
    }
}